package com.kafka;

import org.apache.kafka.clients.producer.KafkaProducer;
import org.apache.kafka.clients.producer.Producer;
import org.apache.kafka.clients.producer.ProducerRecord;
import java.util.Properties;

/**
 * @User 小菜鸡
 * @Data 2020/5/21
 */
public class KafkaApplication {

    public static void main(String[] args) {
        Properties properties = new Properties();
        //连接的服务名和ip
        properties.put("bootstrap.servers","192.168.1.108:9092");
        properties.put("acks","all");
        //重试次数
        properties.put("retries",3);
        //每次发送的数大小，等数据到达这个大小之后就发送数据
        properties.put("batch.size",16384);
        //RecordAccumulator 缓冲区大小
        properties.put("buffer.memory", 33554432);
        //等待时间，就是等待这么久之后就会自动发送数据
        properties.put("linger.ms",1);
        properties.put("key.serializer", "org.apache.kafka.common.serialization.StringSerializer");
        properties.put("value.serializer", "org.apache.kafka.common.serialization.StringSerializer");
        Producer<String, String> producer = new KafkaProducer<String, String>(properties);
        ProducerRecord<String, String> producerRecord = new ProducerRecord<String, String>("first","firstValue");
        producer.send(producerRecord);
        producer.close();
    }
}
